package com.hpjz.common.utils;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.access.BootstrapException;
import org.springframework.stereotype.Component;

@Component
public class BeanFactoryUtils implements BeanFactoryAware {
	
	private static BeanFactory FACTORY;
	

	@Override
	public void setBeanFactory(BeanFactory factory) throws BeansException {
		 FACTORY = factory;
	}
	
	public static Object getBean(String beanName){
		if (FACTORY==null) {
			throw new BootstrapException("Spring Factory is not initalization, please check your BeanFacotryUtils config");
		} else {
              return FACTORY.getBean(beanName);
		}
		
	}

	 
}
